from django.template import Library
from web.forms.project import S28
register = Library()
from django.shortcuts import reverse


@register.inclusion_tag('inclusion/all_project_list.html')
def all_project_list(request):
    my_create_project = S28().py_searche(
        'select * from project where creator_id={0}'.format(
            request.user_id))  # 查所有自己创建项目  1 是项目的名字
    my_invitation_project = S28().py_searche(
        'select * from project where id=(select project_id from invitation where user_information_id={0})'.format(
            request.user_id))  # 查询自己参与的项目   1 是项目的名字


    return {'my': my_create_project, 'join': my_invitation_project, 'request':request}


@register.inclusion_tag('inclusion/manage_menu_list.html')
def manage_menu_list(request):
    data_list = [
        {'title': '概览', 'url': reverse('dashboard', kwargs={'project_id': request.obj[0][0]})},
        {'title': '问题', 'url': reverse('issues', kwargs={'project_id': request.obj[0][0]})},
        {'title': '统计', 'url': reverse('statistics', kwargs={'project_id': request.obj[0][0]})},
        {'title': '配置', 'url': reverse('setting', kwargs={'project_id': request.obj[0][0]})},
        {'title': '文档', 'url': reverse('wiki', kwargs={'project_id': request.obj[0][0]})},
        {'title': '文件', 'url': reverse('file', kwargs={'project_id': request.obj[0][0]})},
    ]
    for i in data_list:
        if request.path_info.startswith(i['url']):
            i['class'] = 'active'
    return {'data_list': data_list}